package dao

import (
	"time"

	"github.com/go-xorm/xorm"

	"im/common"
	"im/dao/es"
	"im/errcode"
	"im/model"
	"im/service/orm"
)

func NewReplysAdmins() replysAdmins {
	return replysAdmins{db: orm.GetDB()}
}

type replysAdmins struct {
	db *xorm.Engine
}

func (p replysAdmins) GetByIds(ids ...int64) ([]model.Replys, error) {
	var ms = []model.Replys{}
	err := p.db.In("id", common.ToInterfaceSlice(ids)...).Find(&ms)
	if err != nil {
		return ms, errcode.NewError(errcode.DaoFailed, err)
	}
	return ms, nil
}
func (p replysAdmins) IndexDoc(id int64, m model.Replys, wait bool) error {
	esM := EsReplysModel{
		Replys: m,
		TimeModelOfEs: model.TimeModelOfEs{
			Created: time.Time(m.TimeModel.Created),
			Updated: time.Time(m.TimeModel.Updated),
		},
	}
	err := es.New().IndexDocWait(IndexNameOfReplys, id, esM, wait)
	return err
}
